export const mockWsData = callback => {
  let index = 0;
  let s = 0;
  let timerId;
  // mock
  const deviceDataMock = [
    { name: "运行时间", serialNumber: "SN001", unit: "s" },
    { name: "温度计", serialNumber: "SN002", unit: "℃" },
    { name: "气压表", serialNumber: "SN003", unit: "hPa" },
    { name: "湿度计", serialNumber: "SN004", unit: "%" },
    { name: "风速计", serialNumber: "SN005", unit: "m/s" },
    { name: "雨量计", serialNumber: "SN006", unit: "mm" },
    { name: "光照计", serialNumber: "SN007", unit: "lux" },
    { name: "电导率计", serialNumber: "SN008", unit: "S/m" },
    { name: "土壤湿度计", serialNumber: "SN009", unit: "%" },
    { name: "噪音计", serialNumber: "SN010", unit: "dB" },
  ];
  const timerTime = 3; // 间隔时间
  // 模拟数据
  timerId = setInterval(() => {
    // 设置新的定时器
    index++;
    s += timerTime;
    const list = [];
    for (let i = 0; i < 10; i++) {
      const random = +(Math.random() * 60).toFixed(2);
      let value = 0;
      if (deviceDataMock[i].unit === "s") {
        value = s;
      } else {
        value = random;
      }
      const item = { type: i + 1, ...deviceDataMock[i], value };
      list.push(item);
    }
    if (s >= 60) s = 0;
    callback(JSON.stringify(list));
  }, timerTime * 1000);
};
